home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
US Department of Defenseā¦ndamentals 1.0 2004 April
/
US Department of Defense: Firewall & Router Fundamentals 1.0 2004 April.iso
/
text_only
/
includes
/
g_functions.js
< prev
next >
Wrap
Text File
|
2004-02-26
|
15KB
|
582 lines
function get_cookie_value(myMasterKey,myDefault)
{
myCookie = document.cookie;
while (myCookie.indexOf("=",0) > -1)
{
i = myCookie.indexOf(";",0);
if (i == -1)
i = myCookie.length;
myPair = myCookie.substring(0,i);
j = myPair.indexOf("=",0);
myKey = myPair.substring(0,j);
if (myKey.substring(0,1) == " ")
myKey = myKey.substring(1,(myKey.length));
myValue = myPair.substring(j+1,(myPair.length));
myCookie = myCookie.substring(i+1,(myCookie.length));
if (myKey == myMasterKey)
{
return myValue;
}
}
return myDefault;
}
function get_sub_cookie_value(myMasterKey,myCookie,myDefault)
{
while (myCookie.indexOf("|",0) > -1)
{
i = myCookie.indexOf("&",0);
if (i == -1)
i = myCookie.length;
myPair = myCookie.substring(0,i);
j = myPair.indexOf("|",0);
myKey = myPair.substring(0,j);
if (myKey.substring(0,1) == " ")
myKey = myKey.substring(1,(myKey.length));
myValue = myPair.substring(j+1,(myPair.length));
myCookie = myCookie.substring(i+1,(myCookie.length));
if (myKey == myMasterKey)
{
return myValue;
}
}
return myDefault;
}
function get_tracking_value(data,key,value_delimiter,pair_delimiter)
{
var return_value = null;
var key_pos = data.indexOf(key,0);
var key_length = key.length + value_delimiter.length;
if (key_pos > -1) {
data = data.substring(key_pos+key_length,data.length);
var end_pos = data.indexOf(pair_delimiter,0);
if (end_pos == -1)
end_pos = data.length
return_value = data.substring(0,end_pos);
}
return return_value;
}
//update get cookie value function, combines both get cookie value and get sub cookie value in one function.
function get_pair_list_value(key,pair_list,default_value,equal_delimiter,pair_delimiter)
{
var tmp_pair = "";
var tmp_value = "";
var return_value = default_value;
var i = -1;
var j = -1;
while (pair_list.indexOf(equal_delimiter,0) > -1)
{
i = pair_list.indexOf(pair_delimiter,0);
if (i == -1)
i = pair_list.length;
tmp_pair = pair_list.substring(0,i);
j = tmp_pair.indexOf(equal_delimiter,0);
tmp_key = tmp_pair.substring(0,j);
if (tmp_key.substring(0,1) == " ")
tmp_key = tmp_key.substring(1,(tmp_key.length));
tmp_value = tmp_pair.substring(j + equal_delimiter.length,(tmp_pair.length));
pair_list = pair_list.substring(i + pair_delimiter.length,(pair_list.length));
if (tmp_key == key)
return_value = tmp_value;
}
return return_value;
}
function set_cookie_value(myKey,myValue)
{
document.cookie = myKey + "=" + myValue + ";path=" + COOKIE_PATH + ";";
}
function get_url_value(myKey)
{
var myURLPos = -1;
var myStr = null;
var myTemp = window.document.location;
if (myTemp != "") {
var myURL = myTemp.toString();
var myOffset = myKey.length + 1;
if (myURL.indexOf('?') > -1) {
//get page
myQS = myURL.substring(myURL.indexOf('?') + 1,myURL.length);
myURLPos = myQS.indexOf(myKey);
if (myURLPos > -1) {
myStr = myQS.substring(myURLPos+myOffset,myQS.length);
if (myStr.indexOf('&') > 0)
myStr=myStr.substring(0,myStr.indexOf('&'));
}
}
}
return myStr;
}
function get_qs_value(qs_key,qs,default_value)
{
qs_value = default_value;
if (qs != "") {
var offset = qs_key.length + 1;
qs = qs.toString();
var qs_pos = qs.indexOf(qs_key);
if (qs_pos > -1) {
qs_value = qs.substring(qs_pos+offset,qs.length);
if (qs_value.indexOf('&') > 0)
qs_value=qs_value.substring(0,qs_value.indexOf('&'));
}
}
return qs_value;
}
function set_qs_value(qs_key,qs_value,qs)
{
var return_qs = "";
if (qs != "") {
var offset = qs_key.length + 1;
qs = qs.toString();
var qs_key_pos = qs.indexOf(qs_key);
if (qs_key_pos > -1) {
qs_value_pos = qs_key_pos+offset;
var qs_left = qs.substring(0,qs_value_pos);
var qs_right = "";
qs_old_value = qs.substring(qs_value_pos,qs.length);
if (qs_old_value.indexOf('&') > 0)
qs_right = qs_old_value.substring(qs_old_value.indexOf('&'),qs_old_value.length);
return_qs = qs_left + qs_value + qs_right;
}
}
else {
return_qs = qs_key + "=" + qs_value;
}
return return_qs;
}
function get_list_value(key,list,pair_delimiter,value_delimiter,default_value)
{
var value = default_value;
if (list != "") {
var offset = key.length + value_delimiter.length;
list = list.toString();
var list_pos = list.indexOf(key);
if (list_pos > -1) {
value = list.substring(list_pos+offset,list.length);
if (value.indexOf(pair_delimiter) > -1)
value = value.substring(0,value.indexOf(pair_delimiter));
}
}
return value;
}
function set_list_value(key,value,list,pair_delimiter,value_delimiter)
{
var return_list = "";
if (list != "") {
var offset = key.length + value_delimiter.length;
list = list.toString();
var key_pos = list.indexOf(key);
if (key_pos > -1) {
value_pos = key_pos+offset;
var left = list.substring(0,value_pos);
var list = list.substring(value_pos,list.length);
var right = list.substring(list.indexOf(pair_delimiter),list.length);
return_list = left + value + right;
}
else {
return_list = list + key + value_delimiter + value + pair_delimiter;
}
}
else {
return_list = key + value_delimiter + value + pair_delimiter;
}
return return_list;
}
function get_item_count(item_list,delimiter)
{
var num_items = -1;
var tmp_return = "nothing";
while (tmp_return != "") {
tmp_return = get_item_in_list(item_list,num_items+2,delimiter);
num_items += 1;
}
return num_items;
}
//1 based, not 0 based
function get_item_in_list(item_list,location,delimiter)
{
var item_value = "";
var tmp_pos = -1;
var tmp_loc = parseInt(location);
for (x = 1; x <= tmp_loc; x++)
{
tmp_pos = item_list.indexOf(delimiter);
if (tmp_pos > -1) {
item_value = item_list.substring(0,tmp_pos);
item_list = item_list.substring(tmp_pos+1,item_list.length);
}
else {
item_value = item_list;
item_list = "";
}
}
return item_value;
}
//1 based, not 0 based
function set_item_in_list(item_list,item_value,location,delimiter)
{
var tmp_pos = -1;
var master_pos = 0;
var tmp_list = item_list;
var tmp_loc = parseInt(location);
if (tmp_loc <= get_item_count(item_list,delimiter)) {
for (x = 1; x <= tmp_loc; x++)
{
tmp_pos = tmp_list.indexOf(delimiter);
if (tmp_pos > -1) {
tmp_list = tmp_list.substring(tmp_pos+1,tmp_list.length);
if (x == tmp_loc) {
item_list = item_list.substring(0,master_pos) + item_value + delimiter + tmp_list;
}
}
else {
//value in last slot, so just add value on the end
item_list = item_list.substring(0,master_pos) + item_value;
}
master_pos += tmp_pos + 1;
}
}
return item_list;
}
function open_popup(page_url,left,top,width,height,scroll,resize,menu)
{
if ((page_url == null) || (page_url == ""))
alert("Popup URL can not be empty.");
else
{
if ((left == null) || (left == ""))
left = "0";
if ((top == null) || (top == ""))
top = "0";
if ((width == null) || (width == ""))
width = "400";
if ((height == null) || (height == ""))
height = "300";
if ((scroll == null) || (scroll == ""))
scroll = "no";
if ((resize == null) || (resize == ""))
resize = "yes";
if ((menu == null) || (menu == ""))
menu = "no";
}
POPUP_WIN=open(page_url,"PopUpWin","left=" + left + ",top=" + top + ",scrollbars=" + scroll + ",resizable=" + resize + ",width=" + width + ",height=" + height + ",toolbar=no,directories=no,menubar=" + menu + ",status=no,");
POPUP_WIN.focus();
}
function parse_string(myString,myDelimiter,myItemNum)
{
var myPos = -1;
var myItem = "";
if ((get_item_count(myString,myDelimiter)+1) >= myItemNum) {
for (i = 1; i <= myItemNum; i++) {
myItem = myString;
myPos = myString.indexOf(myDelimiter);
if (myPos > -1) {
myItem = myString.substring(0,myPos);
myString = myString.substring(myPos+1,myString.length);
}
}
}
return myItem;
}
function convert_num_to_str(myNum,myPlaces)
{
var myNumStr = myNum.toString();
if (myPlaces == null)
myPlaces = 3;
var myZeros = ""
for (y = 1; y < myPlaces; y++) {
for (q = 1; q <= (myPlaces-y); q++) {
myZeros += "0";
}
if (myNumStr.length == y)
myNumStr = myZeros + myNumStr;
myZeros = "";
}
return myNumStr;
}
function convert_boolean_to_num(myBool)
{
if (myBool)
return 1;
else
return 0;
}
function convert_num_to_char(tmp_num)
{
var tmp_str = "";
for (i=0;i<tmp_num.length;i++) {
tmp_str += String.fromCharCode(tmp_num.charCodeAt(i)+20);
}
return tmp_str;
}
function generate_key()
{
var i
var pszK = "";
for (i = 0; i <= 80; i++) {
pszK = pszK + String.fromCharCode(48 + i);
pszK = pszK + String.fromCharCode(122 - i);
i = i + 5;
}
return pszK
}
function encrypt(sStrIn,sKey,cHi,cLow)
{
var iLen
var i
var iChar
var iLastChar
var iLocation
var sEncryptedStr = "";
var cDelta = cHi - cLow + 1;
iLen = sStrIn.length;
//sKey = GenerateKey();
//sKey = myUsername + "KARTAUSER" + myProgID;
iLastChar = sKey.charCodeAt(0);
iLocation = 0;
for (i = 0; i < iLen; i++)
{
iChar = sStrIn.charCodeAt(i);
iChar = iLastChar + iChar + sKey.charCodeAt((i % 40) + 1);
while (iChar > cHi)
{
iChar = iChar - cDelta;
}
iLastChar = sStrIn.charCodeAt(iLocation);
iLocation = iLocation + 1;
sEncryptedStr = sEncryptedStr + String.fromCharCode(iChar);
}
return convertStrToDecStr(sEncryptedStr);
}
function decrypt(sInputStr,sKey,cHi,cLow)
{
var sEncryptedStr
var iLen
var i
var iChar
var iLastChar
var sStrIn
var sStrOut
var iLocation
var sStr = "";
var cDelta = cHi - cLow + 1;
sEncryptedStr = convertDecStrToStr(sInputStr);
//sKey = GenerateKey();
//sKey = myUsername + "KARTAUSER" + myProgID;
iLen = sEncryptedStr.length;
sStrIn = sEncryptedStr;
iLastChar = sKey.charCodeAt(0);
iLocation = 0;
for (i = 0; i < iLen; i++)
{
iChar = sStrIn.charCodeAt(i);
iChar = iChar - iLastChar - sKey.charCodeAt((i % 40) + 1);
while (iChar < cLow)
{
iChar = iChar + cDelta;
}
iLastChar = iChar;
iLocation = iLocation + 1;
sStr = sStr + String.fromCharCode(iChar);
}
return sStr;
}
function get_obj_style(obj_id)
{
if (W3CDOM) {
return eval("document.getElementById('" + obj_id + "').style");
}
else {
if (IE) {
return eval(obj_id + ".style");
}
else {
return eval("document." + obj_id);
}
}
}
function mouse_ov(obj_name)
{
var img_obj = eval("document." + obj_name);
ORIG_IMG.name = obj_name;
ORIG_IMG.src = img_obj.src;
var ov_obj = eval(obj_name + "_OV");
if (LOAD_DONE) {
if (((obj_name == "NEXT") && (DISABLE_NEXT)) || ((obj_name == "PREVIOUS") && (DISABLE_PREV))) {
//nothing
}
else {
if (check_preq(obj_name))
img_obj.src = ov_obj.src;
}
}
}
function mouse(obj_name)
{
if (LOAD_DONE) {
img_obj = eval("document." + obj_name);
img_obj.src = ORIG_IMG.src;
}
}
function open_audio_win(page_num)
{
if (SHOW_AUDIO) {
audio_file = "audio/aud_page" + convert_num_to_str(page_num) + ".htm";
//if (AUDIO_WIN == null)
AUDIO_WIN = window.open(audio_file,"AUDIOWIN","toolbar=no,menubar=no,location=no,height=" + AUDIO_WIN_HEIGHT + ",width=" + AUDIO_WIN_WIDTH + ",resizable=" + AUDIO_WIN_RESIZE + ",scrollbars=" + AUDIO_WIN_SCROLL + ",top=" + AUDIO_WIN_TOP + ",left=" + AUDIO_WIN_LEFT);
//else
// AUDIO_WIN.document.location.href = audio_file;
AUDIO_WIN.focus();
}
}
function get_qs()
{
return "showaudio=" + convert_boolean_to_num(SHOW_AUDIO);
}
function check_preq(obj_name)
{
if (MENU_PREQ) {
var img_obj = eval("document." + obj_name);
if (img_obj.src.indexOf("_de.") > -1)
return false;
}
return true;
}
function convertStrToDecStr(myStr)
{
var myDecStr = "";
for (y = 0; y < myStr.length; y++)
{
myDecStr = myDecStr + myStr.charCodeAt(y) + "/";
}
return myDecStr;
}
function convertDecStrToStr(myDecStr)
{
var myStr = "";
while (myDecStr.indexOf("/",0) > -1)
{
myStr = myStr + String.fromCharCode(myDecStr.substring(0,myDecStr.indexOf("/",0)));
myDecStr = myDecStr.substr(myDecStr.indexOf("/")+1);
}
return myStr;
}
function convert_to_hex(str)
{
var return_str = "";
str = str + "";
for (y = 0; y < str.length; y++)
{
return_str += dec2hex(str.charCodeAt(y));
}
return return_str;
}
function convert_from_hex(str)
{
var return_str = ""
while (str.length > 0)
{
return_str += String.fromCharCode(hex2dec(str.substr(0,2)));
if (str.length == 2)
str = "";
else
str = str.substring(2,str.length);
}
return return_str;
}
function hex2dec(strVal){
// where strVal is a string
// parseInt('ff',16) == 255
return parseInt(strVal,16);
};
function dec2hex(n){
var hex = "0123456789ABCDEF";
var mask = 0xf;
var retstr = "";
while(n != 0)
{
retstr = hex.charAt(n&mask) + retstr;
n>>>=4;
}
return retstr.length == 0 ? "0" : retstr;
}
function item_in_array(tmp_item,tmp_array)
{
for (i=0;i<tmp_array.length;i++) {
if (tmp_item == tmp_array[i])
return true;
}
return false;
}
function get_auto_page_list(num_pages)
{
var tmp_return = "";
for (i=1;i<=parseInt(num_pages);i++) {
tmp_return += "page" + convert_num_to_str(i,3) + ",";
}
tmp_return = tmp_return.substr(0,tmp_return.length-1);
return tmp_return;
}
function get_browse()
{
var tmp_boolean = false
if (get_cookie_value("BROWSE","false") == "true")
tmp_boolean = true;
return tmp_boolean;
}
function set_browse(value)
{
set_cookie_value("BROWSE",value);
}